<?php

require_once ('BaseAjaxModule.php');

class FriendModule extends BaseAjaxModule {

	public function isInFriendTask()	{
		if (!$this->getRequest()->hasParam('id'))	{
			$this->view->setAjaxResponse($this->createErrorResult('ID not defined'));
			return;
		}
		$friend = new Model_Friend();
		$friend->user_id1 = $this->getParam('id');
		$friend->user_id2 = $this->getUser()->id;
		$this->view->result = $friend->isInFriend();
	}
	
	public function acceptRequestTask()	{
		if (!$this->getRequest()->hasParam('id'))	{
			$this->view->setAjaxResponse($this->createErrorResult('ID not defined'));
			return;
		}
		$user = $this->getUser();
		$id = $this->getParam('id');
		$this->view->result = $user->acceptRequest($id);
	}
	
	public function addFriendTask()	{
		if (!$this->getRequest()->hasParam('id'))	{
			$this->view->setAjaxResponse($this->createErrorResult('ID not defined'));
			return;
		}
		$user = $this->getUser();
		$this->view->result = $user->makeRequest($this->getParam('id'));
	}
}
?>